package temaihui.daimaitemai.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

import temaihui.daimaitemai.GoodItemRecommendModel;
import temaihui.daimaitemai.HomeCategoryModel;
import temaihui.daimaitemai.R;

/**
 * Created by sun on 16/7/31.
 */
public class HomeCategoryGridAdapter extends BaseAdapter {
    private List items;
    private Context context;

    static class ViewHolder{
        public TextView textView;
    }
    public HomeCategoryGridAdapter(Context context, List items){
        this.items = items;
        this.context = context;
    }
    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null){
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.home_category_grid_item,null);
            viewHolder.textView = (TextView) convertView.findViewById(R.id.home_category_name);

            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder)convertView.getTag();
        }
        TextView textView = viewHolder.textView;


        HomeCategoryModel goodModel = (HomeCategoryModel) items.get(position);
        textView.setText(goodModel.getCategoryName());

        return convertView;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }
}
